%{
open Ast
%}

/* Tokens */
%token LTE
%token LT
%token GT
%token COMMA
%token L
%token P
%token <string> INT
%token <string> INTCOM
%token <string> IDENT
%token EOF

%left L P
%left INT INTCOM IDENT

/* Points d'entrée */
%type <Ast.req> expression
%start expression
%%

expression:
 | req EOF        { $1 }
;

req:
 | criteria                    { RSimpl ($1)    }
 | criteria COMMA req          { RMult ($1, $3) }
 | criteria req                { RMult ($1, $2) }    
;

criteria:
 | dist LTE INT            { ($1, int_of_string($3)) }
 | dist LTE INTCOM         { let i = String.sub ($3) 0 ((String.length $3) - 1) 
			     in ($1, int_of_string i) }
;

dist:
 | L LT str GT           { L ($3)}
 | P LT str GT           { P ($3)}
;

str:
 | IDENT { $1 }
 | L { "L" }
 | P { "P" }
 | INT { $1 }
 | L str { "L  " ^ ($2) }
 | P str { "P  " ^ ($2) }
 | INT str { ($1) ^ " " ^ ($2) }
 | IDENT str { ($1) ^ " " ^ ($2) }
;
